package top.mcally.liuyi.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.mcally.liuyi.task.ScheduleTaskCron;
import top.mcally.liuyi.task.ScheduleTaskTimer;

/**
 * @author Mcally
 */
@Slf4j
@RestController
@RequestMapping("/test")
@Api(tags = {"测试动态定时"}, description = "测试动态定时")
public class TaskTestController {
    @Autowired
    private ScheduleTaskCron scheduleTask;

    @Autowired
    private ScheduleTaskTimer scheduleTaskTimer;

    @GetMapping("/updateCron")
    @ApiOperation("Cron更新定时时间")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cron", value = "cron 表达式", required = true, dataType = "string", paramType = "query"),
    })
    public String updateCron(String cron) {
        log.info("new cron :{}", cron);
        scheduleTask.setCron(cron);
        return "ok";
    }


    @GetMapping("/updateTimer")
    @ApiOperation("timer更新定时时间,可以任意的时间")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "timer", value = "timer毫秒数", required = true, dataType = "Long", paramType = "query"),
    })
    public String updateTimer(Long timer) {
        log.info("new timer :{}", timer);
        scheduleTaskTimer.setTimer(timer);
        return "ok";
    }
}
